package com.karst.essentials.chapter08
{
	import flash.events.Event;
	
	import org.aswing.AsWingManager;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.parsers.DAE;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	
	internal class ExternalModelsNormalExample extends BasicView
	{
		private var rotX : Number = .1 ;
		private var rotY : Number = .1 ;
		private var easeOut : Number = .1 ;
		private var camYaw : Number = 270 ;
		private var camPitch : Number = 90 ;

		private var model : DisplayObject3D = null ;
		
		public function ExternalModelsNormalExample()
		{
			super();
			createView() ;
			startRendering() ;
		}

		private function createView() : void
		{
			if( model == null )
			{
				model = new DAE() ;
				model.addEventListener( FileLoadEvent.LOAD_COMPLETE, loadedModelHandler ) ;
				DAE( model ).load( "teapot.dae" ) ;
				DAE(model).addFileSearchPath( "." ) ; // 材质搜索文件夹
			}
		}
		
		private function loadedModelHandler( $event : FileLoadEvent ) : void
		{
			scene.addChild( model ) ;
		}
		
		override protected function onRenderTick( $event : Event = null ) : void
		{
			super.onRenderTick( $event ) ;
			camPitch += (( mouseY - AsWingManager.getStage().stageHeight*.5) * rotX - camPitch + 90 ) * easeOut ;
			camYaw += (( mouseX - AsWingManager.getStage().stageWidth*.5) * rotY - camYaw + 270 ) * easeOut ;
			camera.orbit( camPitch, camYaw ) ;
		}
	}
}